package server.consolo;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import qq.message.DataPackage;
import qq.message.DataPackage.MessageType;

public class Test {

	public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException {
		// TODO Auto-generated method stub

		OutputStream serverLog=new FileOutputStream("serverLog");
		
		Socket socket=new Socket("127.0.0.1",8888);
		OutputStream os=socket.getOutputStream();
		InputStream is=socket.getInputStream();
		ObjectOutputStream oos=new ObjectOutputStream(os);
		ObjectInputStream ois = new ObjectInputStream(is);
		DataPackage data=new DataPackage();
		data.setFromName("zhuyi1");
		data.setToName("zhuyi1");
		data.setMessageType(MessageType.LOGIN);
		data.setMessageData("zhuyi1");
		data.setTime(System.currentTimeMillis());
//		System.out.println(data.toString());
		oos.writeObject(data);
		
		DataPackage data2=new DataPackage();
		data2.setFromName("zhuyi1");
		data2.setToName("zhuyi2");
		data2.setMessageType(MessageType.MESSAGE);
		data2.setMessageData("from zhuyi1");
//		oos.writeObject(data2);
		while(true)
		{
			System.out.println("alive");
//			Thread.sleep(100);
			data=(DataPackage) ois.readObject();
			System.out.println(data.getFromName());
//			System.out.println("alive");
//			new DataOutputStream(serverLog).writeLong( System.currentTimeMillis());
//			if(ois.available()>10)
//			{
////				data=(DataPackage) ois.readObject();
//				System.out.println(data.toString());
//				socket.close();
//			}
//			if(is.available()>0)
//			{
//				byte[] buf=new byte[is.available()];
//				is.read(buf);
//				System.out.print(new String(buf,"UTF-8"));
//				socket.close();
//			}
//			
			
		}
	}

}
